package com.atguigu.educms.controller;

import com.atguigu.commonutils.R;
import com.atguigu.educms.entity.CrmBanner;
import com.atguigu.educms.service.CrmBannerService;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * Banner后台管理接口
 */
@RestController
@RequestMapping("/cmsservice/banner")
@CrossOrigin
@Api(description = "幻灯片管理")
public class BannerAdminController {

    @Autowired
    private CrmBannerService bannerService;

    @ApiOperation(value = "分页查询Banner")
    @PostMapping("pageBanner/{page}/{limit}")
    public R pageBanner(@PathVariable Long page, @PathVariable Long limit,
                        @RequestBody(required = false) CrmBanner bannerQuery) {
        Page<CrmBanner> pageModel = bannerService.pageBanner(page, limit);
        
        // 返回分页结果
        return R.ok().data("items", pageModel.getRecords()).data("total", pageModel.getTotal());
    }

    @ApiOperation(value = "添加Banner")
    @PostMapping("addBanner")
    public R addBanner(@RequestBody CrmBanner banner) {
        bannerService.addBanner(banner);
        return R.ok();
    }

    @ApiOperation(value = "根据ID查询Banner")
    @GetMapping("getBannerById/{id}")
    public R getBannerById(@PathVariable String id) {
        CrmBanner banner = bannerService.getBannerById(id);
        return R.ok().data("item", banner);
    }

    @ApiOperation(value = "修改Banner")
    @PostMapping("updateBanner")
    public R updateBanner(@RequestBody CrmBanner banner) {
        bannerService.updateBanner(banner);
        return R.ok();
    }

    @ApiOperation(value = "删除Banner")
    @DeleteMapping("deleteBannerById/{id}")
    public R deleteBannerById(@PathVariable String id) {
        bannerService.deleteBannerById(id);
        return R.ok();
    }
} 